Macros 1.1
authorDavid Tolnay <dtolnay@gmail.com>
Thu, 1 Sep 2016 04:01:36 +0000 (21:01 -0700)
committerDavid Tolnay <dtolnay@gmail.com>
Thu, 1 Sep 2016 04:01:36 +0000 (21:01 -0700)
src/cargo/core/manifest.rs
src/cargo/util/toml.rs
src/doc/manifest.md

index a0e7450574f1eda103914550ac92cc3ec2d02f4b..827008b8be4b190389853766be441bb804c7ee9f 100644 (file)
@@ -61,6 +61,7 @@ pub enum LibKind {
     Lib,
     Rlib,
     Dylib,
+    RustcMacro,
     Other(String),
 }
 
@@ -70,6 +71,7 @@ impl LibKind {
             "lib" => LibKind::Lib,
             "rlib" => LibKind::Rlib,
             "dylib" => LibKind::Dylib,
+            "rustc-macro" => LibKind::RustcMacro,
             s => LibKind::Other(s.to_string()),
         }
     }
@@ -80,6 +82,7 @@ impl LibKind {
             LibKind::Lib => "lib",
             LibKind::Rlib => "rlib",
             LibKind::Dylib => "dylib",
+            LibKind::RustcMacro => "rustc-macro",
             LibKind::Other(ref s) => s,
         }
     }
@@ -88,7 +91,8 @@ impl LibKind {
         match *self {
             LibKind::Lib |
             LibKind::Rlib |
-            LibKind::Dylib => true,
+            LibKind::Dylib |
+            LibKind::RustcMacro => true,
             LibKind::Other(..) => false,
         }
     }
index 0c138e648bf059758854a0746d58743f92d3daad..811e58b49c4ba75d97040179aadaa1888c555f24 100644 (file)
@@ -444,6 +444,7 @@ impl TomlManifest {
         let lib = match self.lib {
             Some(ref lib) => {
                 try!(lib.validate_library_name());
+                try!(lib.validate_crate_type());
                 Some(
                     TomlTarget {
                         name: lib.name.clone().or(Some(project.name.clone())),
@@ -900,6 +901,7 @@ struct TomlTarget {
     bench: Option<bool>,
     doc: Option<bool>,
     plugin: Option<bool>,
+    rustc_macro: Option<bool>,
     harness: Option<bool>,
 }
 
@@ -928,6 +930,7 @@ impl TomlTarget {
             bench: None,
             doc: None,
             plugin: None,
+            rustc_macro: None,
             harness: None,
         }
     }
@@ -1006,6 +1009,14 @@ impl TomlTarget {
             None => Err(human("bench target bench.name is required".to_string()))
         }
     }
+
+    fn validate_crate_type(&self) -> CargoResult<()> {
+        if self.plugin == Some(true) && self.rustc_macro == Some(true) {
+            Err(human("lib.plugin and lib.rustc-macro cannot both be true".to_string()))
+        } else {
+            Ok(())
+        }
+    }
 }
 
 impl PathValue {
@@ -1040,7 +1051,11 @@ fn normalize(lib: &Option<TomlLibTarget>,
               .set_doctest(toml.doctest.unwrap_or(t2.doctested()))
               .set_benched(toml.bench.unwrap_or(t2.benched()))
               .set_harness(toml.harness.unwrap_or(t2.harness()))
-              .set_for_host(toml.plugin.unwrap_or(t2.for_host()));
+              .set_for_host(match (toml.plugin, toml.rustc_macro) {
+                  (None, None) => t2.for_host(),
+                  (Some(true), _) | (_, Some(true)) => true,
+                  _ => false,
+              });
     }
 
     fn lib_target(dst: &mut Vec<Target>,
@@ -1053,6 +1068,7 @@ fn normalize(lib: &Option<TomlLibTarget>,
             Some(kinds) => kinds.iter().map(|s| LibKind::from_str(s)).collect(),
             None => {
                 vec![ if l.plugin == Some(true) {LibKind::Dylib}
+                      else if l.rustc_macro == Some(true) {LibKind::RustcMacro}
                       else {LibKind::Lib} ]
             }
         };
index 675841784d70938793131113360a738048bc824e..086d214d894114f0868d6c62eb7dfbd72a055350 100644 (file)
@@ -508,6 +508,10 @@ doc = true
 # for Cargo to correctly compile it and make it available for all dependencies.
 plugin = false
 
+# If the target is meant to be a "macros 1.1" procedural macro, this field must
+# be set to true.
+rustc-macro = false
+
 # If set to false, `cargo test` will omit the `--test` flag to rustc, which
 # stops it from generating a test harness. This is useful when the binary being
 # built manages the test runner itself.
@@ -527,9 +531,10 @@ name = "..."
 crate-type = ["dylib"] # could be `staticlib` as well
 ```
 
-The available options are `dylib`, `rlib`, `staticlib`, and `cdylib`. You
-should only use this option in a project. Cargo will always compile packages
-(dependencies) based on the requirements of the project that includes them.
+The available options are `dylib`, `rlib`, `staticlib`, `cdylib`, and
+`rustc-macro`. You should only use this option in a project. Cargo will always
+compile packages (dependencies) based on the requirements of the project that
+includes them.
 
 You can read more about the different crate types in the 
 [Rust Reference Manual](https://doc.rust-lang.org/reference.html#linkage)